<?php
class ModelDeviceActivityLog extends Model {
	/*
	 * addActivityLog
	 * 添加设备活动记录
	 * @param int $device_id 设备id
	 * @param string $activity 活动类型
	 * @return boolean
	 */
	public function addActivityLog($device_id,$activity){
		$sql = 'INSERT INTO `device_activity_log` SET `device_id`=:device_id,`activity`=:activity,`date_added`=NOW()';
		$params = array(
			':device_id'=>(int)$device_id,
			':activity'=>$this->db->escape($activity)
		);
		$this->db->query($sql,$params);
		return $this->db->countAffected()>0;
	}

	public function addActivityLogByImei($device_imei,$activity){
		$sql = 'INSERT INTO `device_activity_log` SET `device_id`=(SELECT `device_id` FROM `device` WHERE `device_imei`=:device_imei LIMIT 1),`activity`=:activity,`date_added`=NOW()';
                $params = array(
			':device_imei'=>$this->db->escape($device_imei),
			':activity'=>$this->db->escape($activity)
		);
		$this->db->query($sql,$params);
		return $this->db->countAffected()>0;

	}
}
